'''Given a filename, return a quoted version if necessary
'''
import win32api
import win32con
import regutil
import string
try:
string.index(fname, ' ')
return '"%s"' % fname
except ValueError:
return fname
def LocateFileName(fileNamesString, searchPaths):
'''Locate a file name, anywhere on the search path.
\t If the file can not be located, prompt the user to find it for us
\t (using a common OpenFile dialog)
\t Raises KeyboardInterrupt if the user cancels.
\t'''
import win32api
import win32con
import regutil
import string
import os
fileNames = string.split(fileNamesString, ';')
for path in searchPaths:
for fileName in fileNames:
try:
retPath = os.path.join(path, fileName)
os.stat(retPath)
except os.error:
0
0
fileNames
retPath = None
except:
0
else:
fileName = fileNames[0]
try:
import win32ui
except ImportError:
None if retPath else searchPaths
None if retPath else searchPaths
raise error, 'Need to locate the file %s, but the win32ui module is not available\nPlease run the program again, passing as a parameter the path to this file.' % fileName
except:
None if retPath else searchPaths
flags = win32con.OFN_FILEMUSTEXIST
ext = os.path.splitext(fileName)[1]
filter = 'Files of requested type (*%s)|*%s||' % (ext, ext)
usage = 'regsetup.py - Setup/maintain the registry for Python apps.\n\nRun without options, (but possibly search paths) to repair a totally broken\npython registry setup. This should allow other options to work.\n\nUsage: %s [options ...] paths ...\n-p packageName -- Find and register a package. Looks in the paths for\n a sub-directory with the name of the package, and\n adds a path entry for the package.\n-a appName -- Unconditionally add an application name to the path.\n A new path entry is create with the app name, and the\n paths specified are added to the registry.\n-c -- Add the specified paths to the core Pythonpath.\n If a path appears on the core path, and a package also \n needs that same path, the package will not bother \n registering it. Therefore, By adding paths to the \n core path, you can avoid packages re-registering the same path. \n-m filename -- Find and register the specific file name as a module.\n Do not include a path on the filename!\n--shell -- Register everything with the Win95/NT shell.\n--pythonwin -- Find and register all Pythonwin components.\n--unpythonwin -- Unregister Pythonwin\n--win32com -- Find and register all win32com components\n--upackage name -- Unregister the package\n--uapp name -- Unregister the app (identical to --upackage)\n--umodule name -- Unregister the module\n\n--description -- Print a description of the usage.\n--examples -- Print examples of usage.\n' % sys.argv[0]
description = 'If no options are processed, the program attempts to validate and set \nthe standard Python path to the point where the standard library is\navailable. This can be handy if you move Python to a new drive/sub-directory,\nin which case most of the options would fail (as they need at least string.py,\nos.py etc to function.)\nRunning without options should repair Python well enough to run with \nthe other options.\n\npaths are search paths that the program will use to seek out a file.\nFor example, when registering the core Python, you may wish to\nprovide paths to non-standard places to look for the Python help files,\nlibrary files, etc. When registering win32com, you should pass paths\nspecific to win32com.\n\nSee also the "regcheck.py" utility which will check and dump the contents\nof the registry.\n'
examples = 'Examples:\n"regsetup c:\\wierd\\spot\\1 c:\\wierd\\spot\\2"\nAttempts to setup the core Python. Looks in some standard places,\nas well as the 2 wierd spots to locate the core Python files (eg, Python.exe,\npython14.dll, the standard library and Win32 Extensions.\n\n"regsetup --win32com"\nAttempts to register win32com. No options are passed, so this is only\nlikely to succeed if win32com is already successfully registered, or the\nwin32com directory is current. If neither of these are true, you should pass\nthe path to the win32com directory.\n\n"regsetup -a myappname . .\\subdir"\nRegisters a new Pythonpath entry named myappname, with "C:\\I\\AM\\HERE" and\n"C:\\I\\AM\\HERE\\subdir" added to the path (ie, all args are converted to\nabsolute paths)\n\n"regsetup -c c:\\my\\python\\files"\nUnconditionally add "c:\\my\\python\\files" to the \'core\' Python path.\n\n"regsetup -m some.pyd \\windows\\system"\nRegister the module some.pyd in \\windows\\system as a registered\nmodule. This will allow some.pyd to be imported, even though the\nwindows system directory is not (usually!) on the Python Path.\n\n"regsetup --umodule some"\nUnregister the module "some". This means normal import rules then apply\nfor that module.\n'
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] in [
'/?',
'-?',
'-help',
'-h']:
print usage
elif len(sys.argv) == 1 or not (sys.argv[1][0] in [
'/',
'-']):
searchPath = sys.path[:]
for arg in sys.argv[1:]:
searchPath.append(arg)
searchPath.append('..\\..')
print 'Attempting to setup/repair the Python core'
SetupCore(searchPath)
RegisterShellInfo(searchPath)
print 'Registration complete - checking the registry...'